package com.nike.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


public class NikeDao{
	
	public List<Map<String,Object>> getAllZhanghao(){
		List<Map<String,Object>> list = new ArrayList<Map<String,Object>>();
		Statement stmt = null;
		Connection c = null;
		try {
			Class.forName("com.mysql.jdbc.Driver");
			c = DriverManager
				.getConnection("jdbc:mysql://localhost:3306/nike?user=root&password=123456&useUnicode=true&characterEncoding=utf8");
			c.setAutoCommit(false);
			stmt = c.createStatement();
			String sql = "select email,pwd from zhanghao where registerstatus='0'";
			System.out.println(sql);
			ResultSet rs = stmt.executeQuery(sql);
			while (rs.next()) {
				Map<String,Object> map = new HashMap<String,Object>();
				map.put("email",rs.getString("email"));
				map.put("pwd",rs.getString("pwd"));
				list.add(map);
			}
			stmt.close();
			c.commit();
		} catch (Exception e) {
			e.printStackTrace();
			System.err.println(e.getClass().getName() + ": " + e.getMessage());
		}
		return list;
	}
	public Map<String,Object> getZhanghaoNameOne(){
		Map<String,Object> map = new HashMap<String,Object>();
		Statement stmt = null;
		Connection c = null;
		try {
			Class.forName("com.mysql.jdbc.Driver");
			c = DriverManager
				.getConnection("jdbc:mysql://localhost:3306/nike?user=root&password=123456&useUnicode=true&characterEncoding=utf8");
			c.setAutoCommit(false);
			stmt = c.createStatement();
			String sql = "select name from zhanghaoname order by RAND() limit 1";
			System.out.println(sql);
			ResultSet rs = stmt.executeQuery(sql);
			while (rs.next()) {
				map.put("name",rs.getString("name"));
			}
			stmt.close();
			c.commit();
		} catch (Exception e) {
			e.printStackTrace();
			System.err.println(e.getClass().getName() + ": " + e.getMessage());
		}
		return map;
	}
	public int updateOrderItem(Map<String,String> map) {
		Statement stmt = null;
		int return_int = 0;
		try {
			Class.forName("com.mysql.jdbc.Driver");
			Connection c = DriverManager
				.getConnection("jdbc:mysql://localhost:3306/maotai?user=root&password=123456&useUnicode=true&characterEncoding=utf8");
			c.setAutoCommit(false);
			stmt = c.createStatement();
			String sql = "update zhanghaoorderitem set kuaidiitem='"+map.get("kuaidiitem")+"' where kuaidicode = '"+map.get("kuaidicode")+"'";
			return_int = stmt.executeUpdate(sql);
			stmt.close();
			c.commit();
			c.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.err.println(e.getClass().getName() + ": " + e.getMessage());
		}
		return return_int;
	}
}